package cn.tedu.csmall.passport.controller;

import cn.tedu.csmall.passport.pojo.vo.RoleListItemVO;
import cn.tedu.csmall.passport.service.impl.RoleServiceImpl;
import cn.tedu.csmall.passport.web.JsonResult;
import cn.tedu.csmall.passport.web.ServiceCode;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.spring.web.json.Json;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/roles")
@Api(tags = "02.角色控制器")
public class RoleController {
    @Autowired
    RoleServiceImpl roleService;

    @GetMapping("")
    @ApiOperation("查询管理员列表")
    @ApiOperationSupport(order = 401)
    public JsonResult<List<RoleListItemVO>> list(){
        log.debug("开始处理[查询角色列表]请求,无参数");
        List<RoleListItemVO> list = roleService.list();
        return JsonResult.ok(list);
    }

    @PostMapping("/rebuild")
    @ApiOperation("重建角色列表缓存")
    @ApiOperationSupport(order = 601)
    public JsonResult<Void> rebuildCache(){
        log.debug("开始处理[重建角色列表缓存]请求,无参数");
        roleService.rebuildCache();
        return JsonResult.ok();
    }
}
